package com.jgy.config;

import org.aopalliance.aop.Advice;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.aop.Advisor;
import org.springframework.aop.aspectj.AspectJExpressionPointcut;
import org.springframework.aop.interceptor.CustomizableTraceInterceptor;
import org.springframework.aop.support.DefaultPointcutAdvisor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;

/**
 * @author 姜光远
 * @date 2023/3/3 9:00
 */
@Aspect
@EnableAspectJAutoProxy(proxyTargetClass = true)
@Configuration
public class TraceAopConfig {
    @Pointcut("execution(* com.jgy.controller..*.*(..))")
    public void logOut(){

    }

    /**
     * 日志
     */
    @Bean
    public Advisor traceAdvisor(){
        CustomizableTraceInterceptor interceptor = new CustomizableTraceInterceptor();
        interceptor.setEnterMessage("进入方法名：$[methodName] ：$[methodName]($[argumentsJ)");
        interceptor.setExitMessage("离开方法： $[methodName](): $[returnValue]");
        interceptor.setLogExceptionStackTrace(true);
        AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
        pointcut.setExpression("com.jgy.config.TraceAopConfig.logOut()");
        return new DefaultPointcutAdvisor(pointcut,interceptor);
    }
}
